from scrapy import signals

class FirstbloodDownloaderMiddleware:
    def process_request(self, request, spider):
        # request.headers['User-Agent'] = 'xxx'
        # request.headers['Cookie'] = 'xxx'
        return None

    def process_response(self, request, response, spider):
        # response.text = 'xxx'
        return response

    def process_exception(self, request, exception, spider):
        # 请求的ip被禁掉，该请求就会变成一个异常的请求
        # request.meta['proxy'] = 'http://ip:port'    # 设置代理
        # return request  # 将异常的请求修正后将其进行重新发送
        pass
